package com.etonedu.meals.ui.fragment;

import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.LogUtils;
import com.etonedu.meals.R;
import com.etonedu.meals.base.BaseFragment;
import com.etonedu.meals.common.SPConst;
import com.etonedu.meals.utils.Utils;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import org.greenrobot.eventbus.Subscribe;

public class AddQRFragment extends BaseFragment {

    private ImageView iv_add_qr;
    private TextView tv_add_qr_devcode,tv_add_qr_version,tv_add_qr_model;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_add_qr,null);
        iv_add_qr = view.findViewById(R.id.iv_add_qr);
        tv_add_qr_devcode = view.findViewById(R.id.tv_add_qr_devcode);
        tv_add_qr_version = view.findViewById(R.id.tv_add_qr_version);
        tv_add_qr_model = view.findViewById(R.id.tv_add_qr_model);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        String devCode = Utils.getDevCode();
        String version = Utils.getVersion1(getActivity());
        String model = Build.MODEL;
        tv_add_qr_devcode.setText("设备号："+devCode);
        tv_add_qr_version.setText("APP版本："+version);
        tv_add_qr_model.setText("型号："+model);

        LogUtils.e(model);

        String url = spu.getString(SPConst.ADD_QR);

        Bitmap bitmap = CodeUtils.createImage(url, 400, 400, null);
        iv_add_qr.setImageBitmap(bitmap);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Subscribe
    public void onEvent(String msg) {

    }
}
